<?php

namespace App\Http\Controllers\V1\Api;



use App\Models\V1\Config;
use App\Models\V1\Game;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class GameController extends BaseController
{

    /**
     * 游戏列表-api
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $query=Game::query();
        $id = auth('box')->id();
        $query->where('condition','=',1);
        $query->where('users_id','=',$id);
        $pageSize=$request->input('pageSize',100);
        $sort=$request->input('sort','id');
        $order=$request->input('order','desc');
        $query->orderBy($sort,$order);
        $data=$query->paginate($pageSize);
        return ajax_output(200,"成功",$data);
    }


    /**
     * 增加游戏-api
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {

//        state 状态，1：创建，2：完善资料 3：提交代码 ，4：审核通过 5:审核失败

        $model=new Game();
        $id = auth('box')->id();
        $model->create([
            'users_id'=>$id,
            'name'=>$request->input('name',""),
            'appid'=>$request->input('appid',""),
            'logo'=>$request->input('logo',""),
            'domain'=>$request->input('domain',''),
            'flow'=>$request->input('flow'),
            'state'=>$request->input('state',2)
        ]);
        return ajax_output(200,"成功");
    }

    /**
     * 游戏详情-api
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $vo=Game::find($id);
        return ajax_output(200,"成功",$vo);
    }


    /**
     * 更新游戏-api
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $vo=Game::find($id);
        $vo->update([
            'advert_place_id'=>$request->input('advert_place_id',0),
            'title'=>$request->input('title',""),
            'jump_url'=>$request->input('jump_url',""),
            'thumb'=>$request->input('thumb',""),
            'begin_at'=>$request->input('begin_at'),
            'end_at'=>$request->input('end_at'),
            'state'=>$request->input('state',1)
        ]);
        return ajax_output(200,"成功");
    }

    /**
     * 删除游戏-api
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        Game::destroy($id);
        return ajax_output(200,"成功");
    }
}
